package com.shenggm.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Desc: 登录方法
 * @Author: shenggm
 * @Date: 2023/12/11
 **/
@RestController
@RequestMapping("/login")
public class LoginController {

    @RequestMapping("/doLogin")
    public SaResult doLogin(String username, String passwd) {

        if ("zhangsan".equals(username) && "123456".equals(passwd)){
            StpUtil.login(10001);
            return SaResult.ok("登录成功");
        }
        return SaResult.error("登录失败");

    }

    @RequestMapping("/isLogin")
    public SaResult isLogin(){
        return SaResult.ok("是否登录："+ StpUtil.isLogin());
    }

    @RequestMapping("/tokenInfo")
    public SaResult tokenInfo(){
        return SaResult.data(StpUtil.getTokenInfo());
    }

    @RequestMapping("logout")
    public SaResult logout(){
        StpUtil.logout();
        return SaResult.ok();

    }
}
